home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib.fmt / c / random.man < prev    next >
Encoding:
Text File  |  1989-02-17  |  4.4 KB  |  133 lines

  1.  
  2.  
  3.  
  4. RANDOM                C Library Procedures                 RANDOM
  5.  
  6.  
  7.  
  8. NNAAMMEE
  9.      random, srandom, initstate, setstate - better random number
  10.      generator; routines for changing generators
  11.  
  12. SSYYNNOOPPSSIISS
  13.      lloonngg rraannddoomm(())
  14.  
  15.      ssrraannddoomm((sseeeedd))
  16.      iinntt sseeeedd;;
  17.  
  18.      cchhaarr **iinniittssttaattee((sseeeedd,, ssttaattee,, nn))
  19.      uunnssiiggnneedd sseeeedd;;
  20.      cchhaarr **ssttaattee;;
  21.      iinntt nn;;
  22.  
  23.      cchhaarr **sseettssttaattee((ssttaattee))
  24.      cchhaarr **ssttaattee;;
  25.  
  26. DDEESSCCRRIIPPTTIIOONN
  27.      _R_a_n_d_o_m uses a non-linear additive feedback random number
  28.      generator employing a default table of size 31 long integers
  29.      to return successive pseudo-random numbers in the range from
  30.      0 to (2**31)-1.  The period of this random number generator
  31.      is very large, approximately 16*((2**31)-1).
  32.  
  33.      _R_a_n_d_o_m/_s_r_a_n_d_o_m have (almost) the same calling sequence and
  34.      initialization properties as _r_a_n_d/_s_r_a_n_d. The difference is
  35.      that _r_a_n_d(3) produces a much less random sequence - in fact,
  36.      the low dozen bits generated by rand go through a cyclic
  37.      pattern.  All the bits generated by _r_a_n_d_o_m are usable.  For
  38.      example, ``random()&01'' will produce a random binary value.
  39.  
  40.      Unlike _s_r_a_n_d, _s_r_a_n_d_o_m does not return the old seed; the rea-
  41.      son for this is that the amount of state information used is
  42.      much more than a single word.  (Two other routines are pro-
  43.      vided to deal with restarting/changing random number genera-
  44.      tors).  Like _r_a_n_d(3), however, _r_a_n_d_o_m will by default pro-
  45.      duce a sequence of numbers that can be duplicated by calling
  46.      _s_r_a_n_d_o_m with _1 as the seed.
  47.  
  48.      The _i_n_i_t_s_t_a_t_e routine allows a state array, passed in as an
  49.      argument, to be initialized for future use.  The size of the
  50.      state array (in bytes) is used by _i_n_i_t_s_t_a_t_e to decide how
  51.      sophisticated a random number generator it should use -- the
  52.      more state, the better the random numbers will be.  (Current
  53.      "optimal" values for the amount of state information are 8,
  54.      32, 64, 128, and 256 bytes; other amounts will be rounded
  55.      down to the nearest known amount.  Using less than 8 bytes
  56.      will cause an error).  The seed for the initialization
  57.      (which specifies a starting point for the random number
  58.      sequence, and provides for restarting at the same point) is
  59.      also an argument.  _I_n_i_t_s_t_a_t_e returns a pointer to the
  60.  
  61.  
  62.  
  63. Sprite v1.0            September 29, 1985                       1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RANDOM                C Library Procedures                 RANDOM
  71.  
  72.  
  73.  
  74.      previous state information array.
  75.  
  76.      Once a state has been initialized, the _s_e_t_s_t_a_t_e routine pro-
  77.      vides for rapid switching between states.  _S_e_t_s_t_a_t_e returns
  78.      a pointer to the previous state array; its argument state
  79.      array is used for further random number generation until the
  80.      next call to _i_n_i_t_s_t_a_t_e or _s_e_t_s_t_a_t_e.
  81.  
  82.      Once a state array has been initialized, it may be restarted
  83.      at a different point either by calling _i_n_i_t_s_t_a_t_e (with the
  84.      desired seed, the state array, and its size) or by calling
  85.      both _s_e_t_s_t_a_t_e (with the state array) and _s_r_a_n_d_o_m (with the
  86.      desired seed).  The advantage of calling both _s_e_t_s_t_a_t_e and
  87.      _s_r_a_n_d_o_m is that the size of the state array does not have to
  88.      be remembered after it is initialized.
  89.  
  90.      With 256 bytes of state information, the period of the ran-
  91.      dom number generator is greater than 2**69 which should be
  92.      sufficient for most purposes.
  93.  
  94. AAUUTTHHOORR
  95.      Earl T. Cohen
  96.  
  97. DDIIAAGGNNOOSSTTIICCSS
  98.      If _i_n_i_t_s_t_a_t_e is called with less than 8 bytes of state
  99.      information, or if _s_e_t_s_t_a_t_e detects that the state informa-
  100.      tion has been garbled, error messages are printed on the
  101.      standard error output.
  102.  
  103. SSEEEE AALLSSOO
  104.      rand(3)
  105.  
  106. BBUUGGSS
  107.      About 2/3 the speed of _r_a_n_d(3C).
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. Sprite v1.0            September 29, 1985                       2
  130.  
  131.  
  132.  
  133.